/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pajamas.starter.core.vo;

import org.pajamas.protocol.Builder;

import java.io.Serializable;
import java.util.Date;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

/**
 * @author william
 * @since 2024/1/13
 */
@Schema(description = "unified response body entity")
@Getter
public class ResultVo implements Serializable {
    private static final long serialVersionUID = -4244454450025404995L;
    @Schema(
            description = "current timestamp",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private final long timestamp;
    @Schema(
            description = "response data holder",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED
    )
    private final Object payload;

    private ResultVo(Object payload) {
        this.timestamp = new Date().getTime();
        this.payload = payload;
    }

    @Deprecated
    public ResultVo() {
        this(null);
    }

    public static ResultVoBuilder builder() {
        return new ResultVoBuilder();
    }

    public static class ResultVoBuilder implements Builder<ResultVo> {
        private Object payload;

        private ResultVoBuilder() {
        }

        public ResultVoBuilder payload(Object payload) {
            this.payload = payload;
            return this;
        }

        @Override
        public ResultVo build() {
            return new ResultVo(this.payload);
        }
    }
}
